package org.com.cis.cf.measure;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import org.com.cis.cf.util.SortByPredicted;
import org.com.cis.cf.util.TestPoint;

public class MRRScorer extends MetricScorer { 
	
	public double score(ArrayList<TestPoint> rateList) 
	{
		double score = 0.0;

		int length = rateList.size(), i;
		
		@SuppressWarnings("unchecked")
		Comparator<TestPoint> sortByPredicted = new SortByPredicted();
		Collections.sort(rateList, sortByPredicted);

		for( i = 0; i != length; ++i){
			if(rateList.get(i).getTrue() == 1){
				score = 1.0 /(1+i);
				break;
			}
		}
		return score;
	}
}
